<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>离线化</title>
</head>
<body>
  <img src="./sw-lifecycle.png" alt="">
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('./sw.js', { scope: './' })
        .then(function(work) {
          console.log('sw 完成')
        })
        .catch(function(err) {
          console.log('sw 失败', err)
        })
    }
  </script>
</body>
</html>